'use strict';
// Copyright 2014 Blueant Inc. All Rights Reserved.

/**
 * @fileoverview 材料
 * @author sundbcn@gmail.com (sun debing)
 */

var mongoose = require('mongoose');

///////////////////////////////////////////////////////////
/**
 * 材料
 * @type {mongoose}
 */
var bagPropertySchema = new mongoose.Schema({
    // 材料id
    property_id: {
        type: Number,
        required: true,
        index: true
    },

    // 材料类型
    property_type: {
        type: Number,
        required: true
    },

    // 叠加个数
    stack_num: {
        type: Number,
        default: 1
    }
});

/**
 * 材料类型
 * @return {[type]} [description]
 */
bagPropertySchema.methods.getType = function () {
    return this.property_type;
};

/**
 * 物品id
 * @return {[type]} [description]
 */
bagPropertySchema.methods.getId = function () {
    return this.property_id;
};

/**
 * 叠加的数量
 */
bagPropertySchema.methods.getStackNum = function () {
    return this.stack_num;
};

/**
 * 添加叠加的数量
 */
bagPropertySchema.methods.addStackNum = function () {
    this.stack_num++;
};

/**
 * 减少叠加的数量
 */
bagPropertySchema.methods.subStackNum = function (sub_num) {
    sub_num = sub_num || 1;
    this.stack_num -= sub_num;
};

if (!bagPropertySchema.options.toJSON) {
    bagPropertySchema.options.toJSON = {};
}
/* jshint unused:false */
bagPropertySchema.options.toJSON.transform = function (doc, ret) {
    delete ret._id;
};

module.exports = bagPropertySchema;
